class Solution(object):
    def isCompleteTree(self, root):
        state = 0
        stack = [root]
        while stack:
            next_stack = []
            for node in stack:
                if node.left:
                    if state == 0:
                        next_stack.append(node.left)
                    else:
                        return False
                else:
                    if state == 0:
                        state = 1
                if node.right:
                    if state == 0:
                        next_stack.append(node.right)
                    else:
                        return False
                else:
                    if state == 0:
                        state = 1
            stack = next_stack
        return True

